package org.example.controller;


import org.example.bean.Product;
import org.example.service.Impl.ProductServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ProductController {
    @Autowired
    ProductServise productServise;
    @RequestMapping("/Productlist.do")
    @ResponseBody   //1、修饰当前方法返回类型为JSON
    public List<Product> getAll(){  //2、将需要转换成json格式的对象直接返回
        List<Product> list =  productServise.getAll();
        System.out.println("打印PRODUCT表");
        return list;
    }
    @RequestMapping("/delete3.do")
    public void delete(int id){
        productServise.del(id);
    }
    @RequestMapping("/test3.do")
    public String add(
            @RequestParam("name") String name, @RequestParam("uname") String uname, @RequestParam("tel") long tel
            ,  @RequestParam("text") String text
    ){
        Product product=new Product();
        product.setName(name);
        product.setTel(tel);
        product.setText(text);
        product.setUname(uname);
        productServise.add(product);
        return "产品管理";
    }
    @RequestMapping("/update4.do")
    public String update(@RequestParam("id")int id,@RequestParam("name") String name,@RequestParam("uname") String uname,@RequestParam("tel") long tel
            ,@RequestParam("text") String text){
        Product product=new Product();
        product.setUname(uname);
        product.setName(name);
        product.setTel(tel);
        product.setText(text);
        product.setId(id);
        productServise.update(product);
        return"产品管理";
    }
}
